package com.bw.shop_2302.userlogin

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.mvvm.BaseActivity
import com.bw.shop_2302.R
import com.bw.shop_2302.databinding.ActivityUserLoginBinding
@Route(path = "/app/UserLoginActivity")
class UserLoginActivity : BaseActivity<ActivityUserLoginBinding,UserLoginViewModel>() {


    override fun initView() {

        binding.btLogin.setOnClickListener {

            viewModel.userlogin(binding.etPhone.text.toString(),binding.etPassword.text.toString())

        }

        binding.tvGocode.setOnClickListener {
            ARouter.getInstance().build("/app/LoginCodeActivity").navigation()
        }
    }

    override fun initData() {

        viewModel.loginsuccess.observe(this){

            if(it.code==200){

                ARouter.getInstance().build("/app/User/UserActivity").navigation()
            }
            ToastUtils.showLong(it.message)
        }

        viewModel.loginfail.observe(this){
            ToastUtils.showLong(it)
        }

    }

    override fun getviewmodel(): Class<UserLoginViewModel> = UserLoginViewModel::class.java

    override fun getLayoutID(): Int = R.layout.activity_user_login

}